﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApp5
{
    class 委托和Event事件
    {
        public 委托和Event事件()
        {
            SubFunc subFunc = new SubFunc();
            subFunc.myevent += new MyEventHandler(SubFuncs_Handler);
            subFunc.TestTriggerEvent();
        }

        void SubFuncs_Handler(object sender, string e)
        {
            Console.WriteLine("子类中产生了事件，触发我在Main中执行");
            Console.WriteLine(sender + " " + e);
        }
    }

    public delegate void MyEventHandler(object sender, string e);
    class SubFunc
    {
        public event MyEventHandler myevent;
        public void TestTriggerEvent()
        {
            myevent("你好哦", "test");
        }
    }
}
